package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.DaoGas;
import com.sc.nft.mapper.DaoGasMapper;
import  com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * DaoGas总表(sc_dao_gas)数据DAO
 *
 * @author zxy
 * @since 2023-05-17 15:59:31
 * @description 活动推荐表
 */
@Slf4j
@Repository
public class DaoGasDao extends ServiceImpl<DaoGasMapper, DaoGas> {

    public DaoGas getByDaoId(Long daoId) {
        LambdaQueryWrapper<DaoGas> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DaoGas::getDaoId, daoId);
        return getOne(wrapper);
    }


    public void add(Long id,Integer gas) {
        UpdateWrapper<DaoGas> wrapper = new UpdateWrapper<>();
        wrapper.setSql("last_gas = last_gas + "+gas+" ,sum_gas=sum_gas+ "+ gas  );
        wrapper.eq("id",id);
        update(wrapper);
    }

    public void sub(Long id,Integer gas) {
        UpdateWrapper<DaoGas> wrapper = new UpdateWrapper<>();
        wrapper.setSql("last_gas = last_gas + "+gas+" ,used_gas=used_gas+ "+ gas  );
        wrapper.eq("id",id);
        update(wrapper);
    }

}